﻿using Might.Infrastructure.ModelicaDOM;

namespace Might.Modelica.Annotations.Graphics {
    ///<summary>
    ///</summary>
    public abstract class GraphicsItemEx : GraphicsItem {
        /// <summary>
        /// Public constructor for generic GraphicsPrimtive type.
        /// </summary>
        protected GraphicsItemEx() {
            extent = new GraphicsExtent();
        }

        public override double Width {
            get { return extent.P2.X - extent.P1.X; }
            set {
                extent.P2.X = extent.P1.X + value;
                OnChanged(this, "Width");
            }
        }

        public override double Height {
            get { return extent.P2.Y - extent.P1.Y; }
            set {
                extent.P2.Y = extent.P1.Y + value;
                OnChanged(this, "Height");
            }
        }

        public override double Top {
            get { return extent.P1.Y - ParentExtent.P1.Y; }
            set {
                double delta = ParentExtent.P1.Y + value - extent.P1.Y;
                extent.P1.Y += delta;
                extent.P2.Y += delta;
                OnChanged(this, "Top");
            }
        }

        public override double Left {
            get { return extent.P1.X - ParentExtent.P1.X; }
            set {
                double delta = ParentExtent.P1.X + value - extent.P1.X;
                extent.P1.X += delta;
                extent.P2.X += delta;
                OnChanged(this, "Left");
            }
        }

        #region Specific Modelica members

        /// <summary>
        /// </summary>
        [Mapping("extent")]
        public GraphicsExtent extent { get; set; }
        
        public override bool IsDefault {
            get {
                return base.IsDefault &&
                       extent.IsDefault;
            }
        }

        #endregion
    }
}